package cn.jee.jsp;

import cn.jee.jsp.util.JdbcUtil;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;

@WebServlet("/delStu")
public class DelStuServlet extends  HttpServlet{
@Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    doPost(req,resp);
  }

  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String id=req.getParameter("id");

    String sql="delete from stu where id=?";
    Object[] args={id};
    int row= JdbcUtil.update(sql,args);

    HttpSession session=req.getSession();
    Object clazz_id=session.getAttribute("clazz_id");
    session.setAttribute("stu_msg",row>0?"删除学生成功":"删除学生失败");
    resp.sendRedirect(req.getContextPath()+"/showStus?clazz_id="+clazz_id);
  }
}
